﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace Dal
{
    public class RegionUserDao
    {
        
        public static DataSet getRegionUserReport(string ambient, string distributor)
        {
            string connection = Credentials.getCredentias(ambient);
            if (connection == null)
            {
                return null;
            }
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = new SqlConnection(connection);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            cmd.CommandText = "dbo.dms_Report_ImportRegionUser";
            cmd.Parameters.AddWithValue("@idDistributor", distributor);
            cmd.CommandTimeout = 0;

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataTable dt = new DataTable("dtRegionUser");

            try
            {
                cmd.Connection.Open();
                da.Fill(dt);
                cmd.Connection.Close();
            }
            catch (Exception ex)
            {
                Credentials.writeLogFile("getRegionUserReport: " + ex.Message);
                return null;
            }
            DataSet ds = new DataSet("dsRegionUser");
            ds.Tables.Add(dt);
            return ds;
        }

    }
}
